package com.zytlifeservice.schedule;

import com.zytlifeservice.service.pay.PublicService;
import org.apache.commons.configuration.ConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;

/**
 * Created by MJS on 2017/6/20.
 */

@Component
public class UpdateTokenSchedule {

    private static final Logger logger = LoggerFactory.getLogger(UpdateTokenSchedule.class);

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");

    @Autowired
    private PublicService publicService;

    @Value("${is_product_enviroment}")
    private Boolean isProd;

    @Scheduled(cron = "0 0 1 * * ?")   //每天凌晨1点时更新一次token
    public void updateToken() throws IOException, ConfigurationException {
        if (isProd) {
            publicService.updateToken();
        }
    }
}
